package com.cn.wanxi.servlet.recruitment;

import com.alibaba.fastjson.JSONObject;
import com.cn.wanxi.model.RecruitmentModel;
import com.cn.wanxi.service.IRecruitmentService;
import com.cn.wanxi.service.impl.RecruitmentServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/back/recruitment/recruitmentAdd")
public class recruitmentAddServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
        //2.接收前台传数据过来

        String introduction=req.getParameter("introduction");
        String wages=req.getParameter("wages");
        String address=req.getParameter("address");
        String phone=req.getParameter("phone");
        String mailbox=req.getParameter("mailbox");
        String position=req.getParameter("position");
        String date=req.getParameter("date");

        //3.封装到实体类UserModel
        RecruitmentModel recruitmentModel=new RecruitmentModel();
        recruitmentModel.setIntroduction(introduction);
        recruitmentModel.setWages(wages);
        recruitmentModel.setAddress(address);
        recruitmentModel.setPhone(phone);
        recruitmentModel.setMailbox(mailbox);
        recruitmentModel.setPosition(position);
        recruitmentModel.setDate(date);


        //4.服务逻辑层
        IRecruitmentService iRecruitmentService=new RecruitmentServiceImpl();

        //5.调用得到页面所需要的数据
        int count=iRecruitmentService.recruitmentAdd(recruitmentModel);

        //7.将数据转发到页面
        JSONObject jsonObject=new JSONObject();
        jsonObject.put("count",count);
        resp.getWriter().println(jsonObject);
    }
}
